<script type="text/javascript">
    $(function () {
        $.formValidator.initConfig({
            formID: "admin_rolelist_edit_dialog_form",
            onSuccess: adminRolelistEditDialogFormSubmit,
            submitAfterAjaxPrompt: '有数据正在异步验证，请稍等...',
            inIframe: true
        });
        $("#admin_rolelist_edit_dialog_form_name").formValidator({
            onShow: "请输入角色名称",
            onFocus: "角色名称不能为空"
        }).inputValidator({min: 1, max: 999, onError: "角色名称不能为空"}).ajaxValidator({
            type: "POST",
            url: "/b/admin/check-rolename?id={{.info.Roleid}}",
            data: {
                rolename: function () {
                    return $("#admin_rolelist_edit_dialog_form_name").val()
                }, default: ''
            },
            datatype: "json",
            async: 'false',
            success: function (data) {
                var json = $.parseJSON(data);
                return json.errcode !== 1;
            },
            onError: "角色名称已存在",
            onWait: "请稍候..."
        });
    })
    function adminRolelistEditDialogFormSubmit() {
        $.post('/b/admin/role-edit?id=' + parseInt("{{ .info.Roleid }}"), $("#admin_rolelist_edit_dialog_form").serialize(), function (res) {
            if (res.errcode) {
                $.messager.alert('提示信息', res.errmsg, 'error');
            } else {
                $.messager.alert('提示信息', res.errmsg, 'info');
                $('#admin_rolelist_edit_dialog').dialog('close');
                adminRoleListRefresh();
            }
        })
    }
</script>
<form id="admin_rolelist_edit_dialog_form">
    <table class="dialogtable">
        <tr>
            <td width="80">角色名称：</td>
            <td><input id="admin_rolelist_edit_dialog_form_name" type="text" name="rolename"
                       value="{{ .info.Rolename }}" style="width:180px;height:22px"/></td>
            <td>
                <div id="admin_rolelist_edit_dialog_form_nameTip"></div>
            </td>
        </tr>
        <tr>
            <td>角色描述：</td>
            <td colspan="2"><textarea name="description" style="width:90%;height:60px;font-size:12px">{{.info.Description}}</textarea>
            </td>
        </tr>
        <tr style="display:none;">
            <td>是否启用：</td>
            <td colspan="2">
                {{ if eq .info.Disabled 0 }}
                <label><input type="radio" name="disabled" value="0" checked/>启用</label>
                <label><input type="radio" name="disabled" value="1"/>禁止</label>
                {{else}}
                <label><input type="radio" name="disabled" value="0"/>启用</label>
                <label><input type="radio" name="disabled" value="1" checked/>禁止</label>
                {{end}}
            </td>
        </tr>
        <tr>
            <td>排序：</td>
            <td colspan="2">
                <input type="text" name="listorder" value="{{.info.Listorder}}" style="width:40px;height:22px"/></td>
        </tr>
    </table>
</form>
